#include <bits/stdc++.h>
using namespace std;

const int N = 100005;
int d[N];
int v[N];
int a[N];
int p[N];
int vis[N];
int dis[N];

void so()
{
   int n, m, L, V;
   int cnt = 0;
   memset(vis, 0, sizeof vis);
   memset(dis, 0, sizeof dis);
   cin >> n >> m >> L >> V;
   for(int i = 1; i <= n; i++)
   {
        cin >> d[i] >> v[i] >> a[i];
   }
   for(int i = 1; i<= m; i++)
   {
       cin >> p[i];
       for(int j = 1; j <= n; j++)
       {
           if(vis[j] == 0 && d[j] <= p[i])
           {
               vis[i] = 1;
               if(v[j] > V)
               {
                   cnt++;
                   dis[i]++;
               }
           }
       }
   }
   int sum = 0;
   int t = 0;
   sort(dis + 1, dis + 1 + n);
   for(int i = m; i > 0; i--)
   {
       sum = sum + dis[i];
       if(sum >= cnt)
       {
           t = i;
           break;

       }
   }
   cout << cnt << " ";
   cout << t - 1 << endl;
}

int main()
{
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    int t;
    cin >> t;
    while(t--)
    {
        so();
    }
    return 0;
}
